#ifndef __L0031_0_H__
#define __L0031_0_H__

struct l0031_0_subprocst {
    int index;
    int pipefds[2];                             /* for heartbeat monitor, pipefds[0] for parent read, pipefds[1] for subproc write */
    pid_t pid;
    struct timespec heartbeat_timespec_last;    /* the recent heartbeat in timespec */
};

#define L0031_0_FLAGS_QUIT          1
#define IS_L0031_0_QUIT(L31)                 ((L31)->flags & L0031_0_FLAGS_QUIT)

struct l0031_0st {
    int heartbeat_timeout_s;    /* subprocess heartbeat timeout, should be greater than 10s */
    int nsubprocess;    /* number of subprocesses */
    int flags;
    struct l0031_0_subprocst subprocs[];
};

typedef int (*process_main_proc_t)(void*, void*);    // void* l0031_0_subprocst, void* params
int l0031_0_monitor_start(struct l0031_0st *l31, process_main_proc_t main_entry, void* params);
int l0031_0_heartbeat(struct l0031_0_subprocst *subproc);
struct l0031_0st * l0031_0_monitor_initialize(int nsubprocess, int heartbeat_timeout_s);
#endif // __L0031_0_H__